package com.javaee.controller;

import com.javaee.entity.Activity;
import com.javaee.entity.Course;
import com.javaee.entity.Student;
import com.javaee.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @PostMapping
    public Result add(@RequestBody Student student) {
        boolean flag = studentService.add(student);
        return new Result(flag ? Code.ADD_OK:Code.ADD_ERR,flag);
    }

    @PostMapping("bulkAdd")
    public Result bulkAdd(@RequestBody List<Student> students) {
        boolean flag = studentService.bulkAdd(students);
        return new Result(flag ? Code.ADD_OK:Code.ADD_ERR,flag);
    }

    @PutMapping("/{id}")
    public Result audit(@PathVariable Integer id) {
        boolean flag = studentService.audit(id);
        return new Result(flag ? Code.UPDATE_OK:Code.UPDATE_ERR,flag);
    }

    @PutMapping("/bulkAudit")
    public Result bulkAudit(@RequestBody List<Integer> ids) {
        boolean flag = studentService.bulkAudit(ids);
        return new Result(flag ? Code.UPDATE_OK:Code.UPDATE_ERR,flag);
    }
}
